package org.gwtEss.table.adapter;

import org.gwtEss.client.SimpleVO;
import org.gwtEss.table.SmartUserManagedColWidget;

import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseMoveHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.event.dom.client.MouseUpEvent;
import com.google.gwt.event.dom.client.MouseUpHandler;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant;

public abstract class SmartUserManagedImageColWidget<VO> extends SmartUserManagedColWidget<VO, Image>{
	
	public SmartUserManagedImageColWidget(String colName) {
		super(colName);
		// TODO Auto-generated constructor stub
	}
	protected Image image;
	@Override
	public Image createColWidgetInstance() {
		
		return image = new Image(){
//			{
//				addMouseMoveHandler(new MouseMoveHandler() {
//					
//					@Override
//					public void onMouseMove(MouseMoveEvent event) {
//						SmartUserManagedImageColWidget.this.onMouseMove();
//					}
//
//					
//				});
//				addMouseOutHandler(new MouseOutHandler() {
//					
//					@Override
//					public void onMouseOut(MouseOutEvent event) {
//						SmartUserManagedImageColWidget.this.onMouseOut();
//					}
//				});
//				addMouseOverHandler(new MouseOverHandler() {
//					
//					@Override
//					public void onMouseOver(MouseOverEvent event) {
//						SmartUserManagedImageColWidget.this.onMouseOver();
//					}
//				});
//				addMouseUpHandler(new MouseUpHandler() {
//					
//					@Override
//					public void onMouseUp(MouseUpEvent event) {
//						SmartUserManagedImageColWidget.this.onMouseUp();
//					}
//				});
//			}
		};
	}
//	protected void onMouseUp() {
//		// TODO Auto-generated method stub
//		
//	}
//
//	protected void onMouseOver() {
//		// TODO Auto-generated method stub
//		
//	}
//
//	protected void onMouseOut() {
//		// TODO Auto-generated method stub
//		
//	}
//
//	public  void onMouseMove() {
//		
//	}
	@Override
	public boolean resetData(Image w, VO data) {
		return true;
	}

	@Override
	public void resetWidget(VO data, Image w) {
		String url = fetchImageUrl(data);
		boolean validImage = url != null && !url.trim().equals("");
		w.setVisible(validImage);
		if (validImage)
			w.setUrl(url);

	}
	public Image getImage(){
		return image;
	}

	@Override
	public HorizontalAlignmentConstant alignment(VO data) {
		return HasHorizontalAlignment.ALIGN_CENTER;
	}
	public abstract String fetchImageUrl(VO data);
}
